import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';

import '../../bridge/bridge.dart';
import '../../router/app_route_container.dart';
import 'home_logic.dart';

class HomePage extends StatelessWidget {
  HomePage({Key? key}) : super(key: key);
  final logic = Get.find<HomeLogic>();
  final state = Get.find<HomeLogic>().state;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("HomePage"),
      ),
      body: Column(
        children: [
          const SizedBox(
            height: 20,
          ),
          GestureDetector(
            onTap: () {
              AppRouteContainer.share.openPage(context, "/setting");
            },
            child: const Text(
              "Home to setting",
              style: TextStyle(fontSize: 20),
            ),
          ),
          const SizedBox(
            height: 20,
          ),
          GestureDetector(
            onTap: () {
              state.androidViewData.value += "Add ";
              FlutterBridge.getInstance().flutterToAndroid({'androidView': state.androidViewData.value});
            },
            child: const Text(
              "AndroidView Add",
              style: TextStyle(fontSize: 20),
            ),
          ),
          const SizedBox(
            height: 20,
          ),
          Obx(
            () => SizedBox(
              height: 100,
              child: AndroidView(
                viewType: FlutterBridge.VIEW_TYPE_ID_ANDROID_VIEW, // 和你注册的名字一致
                creationParams: {"androidView": state.androidViewData.value}, // 传递参数
                creationParamsCodec: const StandardMessageCodec(),
              ),
            ),
          )
        ],
      ),
    );
  }
}
